/**
 * @namespace Archetype.methodBuilders.observe
 * Add a specialized "Event.observe" method wish store listening information
 * in order to be disconnected when the component is destroyed.
 */
$N("Archetype.methodBuilders.observe", {
	regexp:"^observe$",

	/**
	 * Acts on the Archetype.Component definition method methodName (that matches "this.regexp")
	 *
	 * @param {Archetype.ComponentDefinition} component
	 * @param {Function} methodName
	 */
	build: function (component, methodName){
		component._private._definition["observe"] = function(element, type, callback) {
			if(!$exist(this._destroy)) {
				this._destroy = $A();
			}
			this._destroy.push("elementEvent");
			this._destroy.push($E(element));
			this._destroy.push(type);
			this._destroy.push(callback);
			$E(element).observe(type, callback);
		}.bind(component._private);
		Logger.log("["+component._private._definition.setup.umn+"."+methodName+"]", "Add observe method on component ");
	}
});